﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Sale.Api.Application.Command.Client;
using Sale.Api.Application.Command.ClientPrice;
using Sale.Api.Application.Command.CType;
using Sale.Api.Application.工单.Command.Client;
using Sale.Domain;
using Sale.Dtos;
using Sale.ErrorCode;

namespace Sale.Api.Controllers
{
    /// <summary>
    /// 客户控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class ClientController : ControllerBase
    {
        private readonly IMediator mediator;

        public ClientController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 客户显示接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<ClientDTO>> GetClient([FromQuery]GetClientCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 客户类型接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<CTypeModel>>> GetCType([FromQuery]GetCTypeCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 添加客户
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddClinent(AddClinentCommand request)
        {
            return await mediator.Send(request);    
        }
       /// <summary>
       /// 删除客户
       /// </summary>
       /// <param name="request"></param>
       /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<int>> DelClinent([FromQuery]DelClinentCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 修改客户
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateClinent(UpdateClinentCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 反填客户
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<ClientModel>>> FanTianClien([FromQuery]FanTianClienCommand request)
        {
            return mediator.Send(request);
        }
    }
}
